package xyz.hujf.tool.并发包原理解析.抽象同步队列;

import org.junit.Test;

import java.util.ArrayList;
import java.util.concurrent.locks.ReentrantLock;

/**
 * @author Hujf
 * @title: MyReetrantLockList
 * @date 2021-04-30 11:18
 * @description: TODO
 */
public class MyReetrantLockList {

    private ArrayList <String>list = new ArrayList();

    private volatile ReentrantLock lock = new ReentrantLock();

    public void add(String e){
        lock.lock();
        try {
            list.add(e);
        }finally {
            lock.unlock();
        }
    }

    public void remove(String e){
        lock.lock();
        try {
            list.add(e);
        }finally {
            lock.unlock();
        }
    }

    public String get(int index){
        lock.lock();
        try {
         return list.get(index);
        }finally {
            lock.unlock();
        }
    }


    @Test
    public void te(){
        MyReetrantLockList a = new MyReetrantLockList();
        a.add("123");
        a.get(0);
    }
}
